<?php
/* 
 *入库质量管理
 */
class In_qcAction extends CommonAction {
    public function _filter(&$map) {
        $key = trim($_REQUEST['keywords']);
        if(!empty($key)) {
            $where['Product.name'] = array('like',"%".$key."%");//产品名称
            $where['Product.ename'] = array('like',"%".$key."%");
            $where['Product.cas'] = array('like',"%".$key."%");//条码
            $where['Buy.mano'] = array('like',"%".$key."%");//条码
            
            $where['_logic'] = "or";
            $map['_complex'] = $where;
        }
        
        if($_REQUEST['status'] != '' )
            $map['Buy.status'] = $_REQUEST['status'];
        else
             $map['status'] = array('egt',1); //开始询价后，就可以进行质量管理
        if( $_REQUEST['in_qc_status'] != '' )
            $map['Buy.in_qc_status'] = $_REQUEST['in_qc_status'];
        if( $_REQUEST['nuclear_result'] != '' )
            $map['Buy.nuclear_result'] = $_REQUEST['nuclear_result'];
        //货前样检测状态
        if( $_REQUEST['sample_qc_status'] != '' ){
            if($_REQUEST['sample_qc_status'] == 7 )//样检订单
                $map['Buy.sample_qc_status'] =  array('between','2,6');
            else
                $map['Buy.sample_qc_status'] = $_REQUEST['sample_qc_status'];
        }
        if( $_REQUEST['pay_status'] != '' )
            $map['Buy.pay_status'] = $_REQUEST['pay_status'];


        $sid = trim($_REQUEST['supplier']);
        if(!empty($sid))
            $map['sname'] = array('like',"%".$sid."%");
        $od_mano = trim($_REQUEST['order_detail_mano']);
        if(!empty($od_mano))
            $map['Order_detail.mano'] = array('like',"%".$od_mano."%");
        /*
        if(!empty($_REQUEST['order_mano']))
            $map['Sale.mano'] = array('like',"%".$_REQUEST['order_mano']."%");*/


         //time 
        $cond_time = array();
        if( $_REQUEST['start_time'] != '' )
          array_push($cond_time, array( 'egt' , strtotime($_REQUEST['start_time']) ) );
          //$cond_time = array( 'egt' , strtotime($_REQUEST['start_time']) );
        if( $_REQUEST['end_time'] != '' )
          array_push($cond_time, array( 'elt' , strtotime($_REQUEST['end_time']) ) );

        //选择了时间类型,并且时间不为空，则按时间进行搜索
        if( $_REQUEST['time_type'] != "" && 
          ($_REQUEST['end_time'] != '' ||  $_REQUEST['start_time'] != '' ) ){
            switch ($_REQUEST['time_type']) {
              case '1': //出图时间
                $map['Buy.nuclear_drawing_time '] = $cond_time;
                break;
              /*case '2': //创建时间
                $map['Order_detail.create_time '] = $cond_time;
                break;
              
              default:  //按下单时间查询
                $map['Order_detail.create_time '] = $cond_time;
                break; */
            }
            
        }


    }

    public function index(){
        if(!empty($_REQUEST['order_detail_mano']))
            parent::index('BuyOrderView');
        else
            parent::index('BuyView');
    }

    public function edit(){
        $model = M ( 'Buy');
        $id = $_REQUEST [$model->getPk ()];
        $vo = $model->getById ( $id );
        $this->assign ( 'vo', $vo );
        $this->display ();
    }

    public function update()
    {
        A('Buy')->update();
    }
}
?>
